<?php
/*
 * 进云智能生成平台
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
 */
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
if($_RQ['op']=='get'){
	$mobile=pdo_getcolumn('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'mobile');
	$return=array();
	$return['mobile']=$mobile;
	$return['item']=array();
	set_html('title','绑定手机号码');
	exi($return);
}
if($_RQ['op']=='send_verifycode'){
	$post=get_postdata();
	$mobile=$post['mobile'];
	$code=rand(1000,9999);
	$_SESSION['verify_code']=$code;
	$_SESSION['verify_mobile']=$mobile;
	$content=array('code'=>$code);
	$setting=uni_setting('member_setting');
	$mid=$setting['sms_mb']['login'];
	
	$result=cfc('core')->sendsms($mobile,$content,$mid);
	if($result){
		exi('success');
	}else{
		exi('error');
	}

}
if($_RQ['op']=='post'){
	$post=get_postdata();
	if(empty($post['mobile'])){
		exi('请输入手机号！','error');
	}
	if(empty($post['yzm'])){
		exi('请输入验证码！','error');
	}
	if(trim($post['yzm'])==$_SESSION['verify_code']&&trim($post['mobile'])==$_SESSION['verify_mobile']){
	$data=array('mobile'=>$post['mobile']);
	pdo_update('core_members',$data,array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$event=array(
		'mobile'=>$post['mobile'],
		'mid'=>$_SESSION['uid'],
		'time'=>time(),
	);
	publish('core','member.mobile',$event);
		exi('绑定成功！','','goback');
	}else{
		exi('验证码错误','error');
	}
}